import { persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage'

import { 
    LOAD_SELECTED_COMMUNITY_CATEGORY_DATA,
    LOAD_SELECTED_BLOG_DATA,
} from '../actions/CommunityActions';

const initialState = {
    error: null,
    communityCategoryData: {},
    communityBlog: {},
}

const persistConfig = {
    key: 'community',
    storage,
    whitelist: ['communityCategoryData', 'communityBlog'], // place to select which state you want to persist
}

const communityReducer = (state = initialState, action) => {
    switch (action.type) {
        case LOAD_SELECTED_COMMUNITY_CATEGORY_DATA:
            return {
                ...state,
                communityCategoryData: action.data,
            }
        case LOAD_SELECTED_BLOG_DATA:
            return {
                ...state,
                communityBlog: action.data,
            }
        default:
            return {...state};
    }
};

export default persistReducer(persistConfig, communityReducer);